package name.fowler.refactoring.simplestore.dao;

import name.fowler.refactoring.simplestore.BaseEntity;
import name.fowler.refactoring.simplestore.Customer;

import javax.persistence.*;
import java.util.List;
import java.util.Map;

/* simple dao example */

public class CrudDao{

	    private EntityManager em;

	    public CrudDao(EntityManager em) {
	        this.em = em;
	    }

	    public void create(Customer customer) {
	        em.persist(customer);
	    }

	    public List<Customer> readAll() {
	        return em.createQuery("select c from Customer c", Customer.class).getResultList();
	    }

	    public Customer update(Customer customer) {
	        return  em.merge(customer);
	    }

	    public void delete(Customer customer) {
	        em.remove(customer);
	    }
	

}

